﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shsc.Net.Common.Validator;
using Shsc.Net.Common.Resource;

namespace Shsc.Net.Common.Exeption
{
    public class ValidatorException : BaseException
    {
        public ValidatorResultList ValidatorResultList { get; set; }

        public ValidatorResult ValidatorResult { get; set; }

        public ValidatorException()
        {
            ValidatorResultList = new ValidatorResultList();
        }

        public ValidatorException(string _messageId, params string[] _param)
            : base(_messageId, _param)
        {
            MessageId = _messageId;
            Param = _param;
            ValidatorResultList = new ValidatorResultList();
            CreateMessage();
        }

        private void CreateMessage()
        {
            ValidatorResult result = new ValidatorResult();
            result.MessageContent = MessageUtil.getMessage(MessageId, "",
                Constants.ErrorMessageResourcePath, Param);
            ValidatorResultList.Add(result);
        }

        public override string Message
        {
            get
            {
                StringBuilder sb = new StringBuilder();
                if (string.IsNullOrEmpty(this.MessageId))
                {
                    for (int i = 0; i < ValidatorResultList.Count; i++)
                    {
                        sb.Append(ValidatorResultList[i].MessageContent);
                        sb.Append("\r\n");
                    }
                }
                else
                {
                    sb.Append(base.Message);
                }
                return sb.ToString();
            }
        }
    }
}
